package org.jsola.contract.helper;

import org.jsola.common.SafeKit;
import org.jsola.contract.dto.ContractPayLogAddDTO;
import org.jsola.contract.dto.ContractPayLogUpdateDTO;
import org.jsola.contract.entity.ContractPayLogDO;
import org.jsola.contract.query.ContractPayLogQuery;
import org.jsola.contract.service.IContractPayLogService;
import org.jsola.contract.vo.ContractPayLogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.contract.core.AbstractTest.SITE_ID;



/**
 * 租户电子合同充值记录
 *
 * @author JanusMix
 */
@Component
public class ContractPayLogTestHelper extends BaseTestHelper {
    
    @Autowired
    private IContractPayLogService contractPayLogService;

    /**
     * 生成add测试数据
     * @return ContractPayLogAddDTO
     */
    public ContractPayLogAddDTO getContractPayLogAddDTO(){
        ContractPayLogAddDTO contractPayLogAddDTO = new ContractPayLogAddDTO();
        contractPayLogAddDTO.setQuotaPay(SafeKit.getInteger(getRandomValue("int",11)));
        return contractPayLogAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ContractPayLogUpdateDTO
     */
    public ContractPayLogUpdateDTO getContractPayLogUpdateDTO(ContractPayLogVO contractPayLogVO){
        return contractPayLogService.selectDOById(contractPayLogVO.getId(), SITE_ID).to(ContractPayLogUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ContractPayLogQuery
     */
    public ContractPayLogQuery getContractPayLogQuery() {
        ContractPayLogQuery contractPayLogQuery = new ContractPayLogQuery();
        List<ContractPayLogDO> contractPayLogDOList = contractPayLogService.list(new ContractPayLogDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(contractPayLogDOList)) {
            ContractPayLogDO contractPayLogDO = contractPayLogDOList.get(0);
            contractPayLogQuery = contractPayLogDO.to(ContractPayLogQuery.class);
        }
        return contractPayLogQuery;
    }

    /**
     * 保存示例
     * @return ContractPayLogVO
     */
    public ContractPayLogVO saveContractPayLogExample(){
        ContractPayLogAddDTO addDTO = this.getContractPayLogAddDTO();
        ContractPayLogVO contractPayLogVO = contractPayLogService.save(addDTO,buildTokenUser());
        return contractPayLogVO;
    }


}

